"""确认历史模型"""
from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey, func
from sqlalchemy.orm import relationship
from app.database import Base


class ConfirmHistory(Base):
    """确认历史表"""
    __tablename__ = "confirm_history"

    id = Column(Integer, primary_key=True, index=True)
    issue_id = Column(Integer, ForeignKey("scan_issues.id", ondelete="CASCADE"), nullable=False, comment="问题ID")
    confirm_type = Column(String(50), nullable=False, comment="确认类型")
    confirmed_by = Column(String(100), nullable=False, comment="确认人")
    confirmed_at = Column(DateTime, server_default=func.now(), nullable=False, comment="确认时间")
    confirm_comment = Column(Text, comment="确认备注")
    action_type = Column(String(20), nullable=False, comment="操作类型: confirm/modify/revoke")
    from_type = Column(String(50), comment="修改前类型(仅modify操作)")
    to_type = Column(String(50), comment="修改后类型(仅modify操作)")
    created_at = Column(DateTime, server_default=func.now(), comment="创建时间")

    # 关系
    issue = relationship("Issue", back_populates="confirm_history")

